package com.lyw.GeoLocationClient.service;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;

public class MyAlarmManager {

    private Context mContext;
    private AlarmManager mAlarmManager;
    PendingIntent collectSender;

    public MyAlarmManager(Context context) {
        mContext = context;
        mAlarmManager = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE);
        Intent collectIntent = new Intent(mContext, LBSClient.class);
        collectSender
                = PendingIntent.getService(mContext, 0, collectIntent, 0);
    }

    public void startAlarm(int repeat) {
        if (mAlarmManager != null) {
            mAlarmManager.cancel(collectSender);
            mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP
                    , SystemClock.elapsedRealtime()
                    , repeat
                    , collectSender);
        }
    }

    public void stop() {
        mAlarmManager.cancel(collectSender);
    }
}
